<template>
  <iframe :id="id"
          :src="url"
          frameborder="0"
          width="100%"
          height="800px"
          scrolling="auto"></iframe>
</template>

<script>
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'

export default {
  name: 'IframePageContent',
  inject: ['closeCurrent'],
  data () {
    return {
      url: '',
      id: ''
    }
  },
  created () {
    this.goUrl()
  },
  updated () {
    this.goUrl()
  },
  watch: {
    $route (to, from) {
      this.goUrl()
    }
  },
  methods: {
    goUrl () {
      let url = this.$route.meta.url
      let id = this.$route.path
      this.id = id
      // url = "http://www.baidu.com"
      // console.log("------url------"+url)
      if (url !== null && url !== undefined) {
        this.url = url
        if (this.$route.meta.isBlank !== undefined && this.$route.meta.isBlank === '1') {
          this.closeCurrent()
          // 外部url加入token
          let tokenStr = '${token}'
          if (url.indexOf(tokenStr) !== -1) {
            let token = Vue.ls.get(ACCESS_TOKEN)
            this.url = url.replace(tokenStr, token)
          }
          window.open(this.url, '_blank')
        }
      }
    }
  }
}
</script>

<style>
</style>
